<?

define ('IN_ANNOUNCE', true);
require_once('./include/core_announce.php');

$r = "d" . benc_str("files") . "d";

$fields = "info_hash, times_completed, seeders, leechers";

if (!isset($_GET["info_hash"]))	 die();
else {
	$quotes=get_magic_quotes_gpc();
	preg_match_all('%info_hash=(.*?)(\&|$)%si',$_SERVER['QUERY_STRING'],$d);
	$counter=0;
	foreach($d[1] as $hash ) {
		$hash=urldecode($hash);
		if (strlen($hash) != 20) err("Invalid info-hash (".strlen($hash).")");	
		if ( $quotes ) $hash = bin2hex(stripslashes($hash));
		else $hash = bin2hex($hash);
		
		if ( $counter==0 ) $where.=' info_hash = ' . sqlesc($hash);
		else $where.=' OR info_hash = ' . sqlesc($hash);
		$counter++;
	}
	$query = 'SELECT '.$fields.' FROM torrents WHERE '.$where;

}

$res=mysql_query($query) or err(mysql_error());

while ($row = mysql_fetch_assoc($res)) {
	$r .= "20:" . pack("H*", ($row["info_hash"])) . "d" .
		benc_str("complete") . "i" . $row["seeders"] . "e" .
		benc_str("downloaded") . "i" . $row["times_completed"] . "e" .
		benc_str("incomplete") . "i" . $row["leechers"] . "e" .  "e";
}
$r .= "ee";
header("Content-Type: text/plain");
header("Pragma: no-cache");
print($r);

?>